package com.ruoyi.merchant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.merchant.dto.AbilityassessmentReportDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.merchant.domain.AbilityassessmentReport;
import com.ruoyi.merchant.service.IAbilityassessmentReportService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 能力评估-评估报告Controller
 * 
 * @author chengxin.ju
 * @date 2023-12-24
 */
@Slf4j
@RestController
@RequestMapping("/report")
public class AbilityassessmentReportController extends BaseController
{
    @Autowired
    private IAbilityassessmentReportService abilityassessmentReportService;

    /**
     * 查询能力评估-评估报告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AbilityassessmentReport abilityassessmentReport)
    {
        startPage();
        List<AbilityassessmentReport> list = abilityassessmentReportService.selectAbilityassessmentReportList(abilityassessmentReport);
        return getDataTable(list);
    }

    /**
     * 导出能力评估-评估报告列表
     */
    @Log(title = "能力评估-评估报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AbilityassessmentReport abilityassessmentReport)
    {
        List<AbilityassessmentReport> list = abilityassessmentReportService.selectAbilityassessmentReportList(abilityassessmentReport);
        ExcelUtil<AbilityassessmentReport> util = new ExcelUtil<AbilityassessmentReport>(AbilityassessmentReport.class);
        util.exportExcel(response, list, "能力评估-评估报告数据");
    }

    /**
     * 初始化评估报告 主要是客户基本信息 和报告评级
     * @author zhaocaisen
     * @param abilityassessmentReport
     * @return BaseResultEntity
     * @since 2020-06-05
     */
    @ResponseBody
    @RequestMapping(value = "/initReport",method = RequestMethod.POST)
    public AjaxResult initReport(@RequestBody AbilityassessmentReport abilityassessmentReport){
        AbilityassessmentReportDto abilityassessmentReportDto = null;
        try{
            abilityassessmentReportDto =  abilityassessmentReportService.initReport(abilityassessmentReport);
            if(abilityassessmentReportDto == null){
                return error("初始化失败");
            }
        }catch (Exception e){
            log.error("AssessentAbilityController.initReport",e);
            return error("初始化失败");
        }
        return success(abilityassessmentReportDto);
    }

    /**
     * 获取能力评估-评估报告详细信息
     */
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(abilityassessmentReportService.selectAbilityassessmentReportByBaseId(baseId));
    }

    /**
     * 新增能力评估-评估报告
     */
    @Log(title = "能力评估-评估报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AbilityassessmentReport abilityassessmentReport)
    {
        return toAjax(abilityassessmentReportService.insertAbilityassessmentReport(abilityassessmentReport));
    }

    /**
     * 修改能力评估-评估报告
     */
    @Log(title = "能力评估-评估报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AbilityassessmentReport abilityassessmentReport)
    {
        return toAjax(abilityassessmentReportService.updateAbilityassessmentReport(abilityassessmentReport));
    }

    /**
     * 删除能力评估-评估报告
     */
    @Log(title = "能力评估-评估报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(abilityassessmentReportService.deleteAbilityassessmentReportByBaseIds(baseIds));
    }
}
